package com.probox.common.entity.service.recharge.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.probox.common.core.utils.DateUtils;
import com.probox.common.core.utils.StringUtils;
import com.probox.common.entity.domain.recharge.RechargeRecord;
import com.probox.common.entity.mapper.recharge.RechargeRecordMapper;
import com.probox.common.entity.service.recharge.IRechargeRecordService;
import com.probox.common.entity.vo.recharge.RechargeRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * 储值记录Service业务层处理
 *
 * @author usoft
 * @date 2022-11-02
 */
@Service
@Transactional
public class RechargeRecordServiceImpl extends ServiceImpl<RechargeRecordMapper, RechargeRecord> implements IRechargeRecordService {
    @Autowired
    private RechargeRecordMapper rechargeRecordMapper;


    /**
     * 储值明细列表
     *
     * @param vo
     * @return
     */
    @Override
    public List<RechargeRecordVo> getList(RechargeRecordVo vo) {
        return rechargeRecordMapper.getList(vo);
    }

    /**
     * 查询储值记录
     *
     * @param recordId 储值记录ID
     * @return 储值记录
     */
    @Override
    public RechargeRecord selectRechargeRecordById(Long recordId) {
        return this.getById(recordId);
    }

    @Override
    public RechargeRecord selectRecharge(Long rechargeId, Long customerId) {

        QueryWrapper<RechargeRecord> queryWrapper = Wrappers.query();
        queryWrapper.eq("recharge_id", rechargeId);
        queryWrapper.eq("member_id", customerId);
        queryWrapper.last(" order by record_id desc limit 1");
        return rechargeRecordMapper.selectOne(queryWrapper);
    }

    /**
     * 查询储值记录列表
     *
     * @param rechargeRecord 储值记录
     * @return 储值记录
     */
    @Override
    public List<RechargeRecord> queryList(RechargeRecord rechargeRecord) {
        QueryWrapper<RechargeRecord> queryWrapper = Wrappers.query();
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getRecordId())) && rechargeRecord.getRecordId() != null) {
            queryWrapper.eq("record_id", rechargeRecord.getRecordId());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getRechargeId())) && rechargeRecord.getRechargeId() != null) {
            queryWrapper.eq("recharge_id", rechargeRecord.getRechargeId());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getIsCommon())) && rechargeRecord.getIsCommon() != null) {
            queryWrapper.eq("is_common", rechargeRecord.getIsCommon());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getRechargeName())) && rechargeRecord.getRechargeName() != null) {
            queryWrapper.eq("recharge_name", rechargeRecord.getRechargeName());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getIsRecommend())) && rechargeRecord.getIsRecommend() != null) {
            queryWrapper.eq("is_recommend", rechargeRecord.getIsRecommend());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getRechargeIcon())) && rechargeRecord.getRechargeIcon() != null) {
            queryWrapper.eq("recharge_icon", rechargeRecord.getRechargeIcon());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getStoreId())) && rechargeRecord.getStoreId() != null) {
            queryWrapper.eq("store_id", rechargeRecord.getStoreId());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getMemberId())) && rechargeRecord.getMemberId() != null) {
            queryWrapper.eq("member_id", rechargeRecord.getMemberId());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getRechargeMoney())) && rechargeRecord.getRechargeMoney() != null) {
            queryWrapper.eq("recharge_money", rechargeRecord.getRechargeMoney());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getFirstDouble())) && rechargeRecord.getFirstDouble() != null) {
            queryWrapper.eq("first_double", rechargeRecord.getFirstDouble());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getGoldCoin())) && rechargeRecord.getGoldCoin() != null) {
            queryWrapper.eq("gold_coin", rechargeRecord.getGoldCoin());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getSilverCoin())) && rechargeRecord.getSilverCoin() != null) {
            queryWrapper.eq("silver_coin", rechargeRecord.getSilverCoin());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getScore())) && rechargeRecord.getScore() != null) {
            queryWrapper.eq("score", rechargeRecord.getScore());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getRechargeDesc())) && rechargeRecord.getRechargeDesc() != null) {
            queryWrapper.eq("recharge_desc", rechargeRecord.getRechargeDesc());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getDataStatus())) && rechargeRecord.getDataStatus() != null) {
            queryWrapper.eq("data_status", rechargeRecord.getDataStatus());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getCreateUser())) && rechargeRecord.getCreateUser() != null) {
            queryWrapper.eq("create_user", rechargeRecord.getCreateUser());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getCreateName())) && rechargeRecord.getCreateName() != null) {
            queryWrapper.eq("create_name", rechargeRecord.getCreateName());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getUpdateUser())) && rechargeRecord.getUpdateUser() != null) {
            queryWrapper.eq("update_user", rechargeRecord.getUpdateUser());
        }
        if (StringUtils.isNotEmpty(String.valueOf(rechargeRecord.getUpdateName())) && rechargeRecord.getUpdateName() != null) {
            queryWrapper.eq("update_name", rechargeRecord.getUpdateName());
        }
        return rechargeRecordMapper.selectList(queryWrapper);
    }

    /**
     * 新增储值记录
     *
     * @param rechargeRecord 储值记录
     * @return 结果
     */
    @Override
    public boolean insertRechargeRecord(RechargeRecord rechargeRecord) {

        return this.save(rechargeRecord);

    }

    /**
     * 修改储值记录
     *
     * @param rechargeRecord 储值记录
     * @return 结果
     */
    @Override
    public boolean updateRechargeRecord(RechargeRecord rechargeRecord) {

        return this.updateById(rechargeRecord);
    }

    /**
     * 批量删除储值记录
     *
     * @param recordIds 需要删除的储值记录ID
     * @return 结果
     */
    @Override
    public boolean deleteRechargeRecordByIds(Long[] recordIds) {
        return this.removeByIds(Arrays.asList(recordIds));
    }


}
